package com.situ.mall.config;

import com.situ.mall.interceptor.LoginInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 配置类 与拦截器联动
 **/
@Configuration
public class WebConfigurer implements WebMvcConfigurer {
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //请求相关操作
        registry.addInterceptor(new LoginInterceptor())
                //拦截路径
                .addPathPatterns("/cart/**").addPathPatterns("/order/**");
    }

    //配置虚拟路径
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        //<img src="/pic/1.png">
        //建立一种映射
        registry.addResourceHandler("/pic/**").addResourceLocations("file:/D:/mypic/");
        WebMvcConfigurer.super.addResourceHandlers(registry);
    }
}